home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MAIL.SWG / 0021_Writing JAM Base Messages.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  4KB  |  127 lines

  1. {
  2. > Is there somebody who can give me an example of
  3. > how to write an JAM Base message (RemoteAccess) ?
  4.  
  5. > I already have JAMAPI and MKMSG I'll need just an simple unit how to
  6. > write fast and simple an message to the JAM base..
  7.  
  8. Try this... It should work with the standard JAMAPI (I think, at least I
  9. can't remember changing anything in it). It's a little piece of testcode
  10. I wrote to play around with JAM :
  11. }
  12. Program JAMTest;
  13.  
  14. Uses
  15.   JAM, JAMmb, JAMcrc32;
  16.  
  17. Var
  18.   JAMMsg     : JAMAPIPTR;
  19.   ToUsername : String[100];
  20.   Position   : LongInt;
  21.   S          : String;
  22.   MsgNo      : LongInt;
  23.   Error      : Boolean;
  24.  
  25. Function FileLength (Handle:INTEGER) : LongInt;
  26. Var
  27.   Position : LongInt;
  28. Begin
  29.   Position   := JAMMsg^.SeekFile (Handle, 1, 0);
  30.   FileLength := JAMMsg^.SeekFile (Handle, 2, 0);
  31.   JAMMsg^.SeekFile (Handle, 0, Position);
  32. End; { FileLength }
  33.  
  34.  
  35. Begin
  36.   New (JAMMsg, Init);
  37.   New (JAMMsg^.WorkBuf);
  38.   With JAMMsg^ Do
  39.   Begin
  40.     If (WorkBuf <> NIL) Then
  41.     Begin
  42.       WorkLen  := SizeOf(JAMBUF);
  43.       BaseName := 'ANOTHER';
  44.  
  45.       Error := Not OpenMB;
  46.       If Error Then Error := Not CreateMB;
  47.       If Not Error Then
  48.       Begin
  49.         If LockMB(True) Then
  50.         Begin
  51.  
  52.           MsgNo := (FileLength(IdxHandle) Div SizeOf(JAMIDXREC)) +
  53.                    HdrInfo.BaseMsgNum;
  54.           Hdr.MsgNum := MsgNo;
  55.  
  56.           (* Add an index record *)
  57.           ToUsername := 'Marco Miltenburg';
  58.           With Idx Do
  59.           Begin
  60.             S := ToUsername;
  61.             LowCaseBuf (S[1], Length(S));
  62.             UserCRC   := crc32(S[1], Length(S), -1);
  63.             HdrOffset := FileLength (JAMMsg^.HdrHandle);
  64.           End;
  65.           StoreMsgIdx(MsgNo);
  66.  
  67.           Position := 1;
  68.           FillChar (Workbuf^, SizeOf(WorkLen), #0);
  69.           S := 'This is a test in JAM.'#13#10;
  70.           AddField (0, FALSE, Length(S), Position, S[1]);
  71.           S := '--- WhatEver/386 v0.0'#13#10;
  72.           AddField (0, FALSE, Length(S), Position, S[1]);
  73.           Hdr.TxtLen := Position - 1;
  74.           Hdr.TxtOffset := FileLength(TxtHandle);
  75.           StoreMsgTxt;
  76.  
  77.           FillChar (Workbuf^, SizeOf(WorkLen), #0);
  78.           S := 'WhatEven/386 v0.0'; Position := 1;
  79.           AddField (2, TRUE, Length(S), Position, S[1]);
  80.           S := ToUserName;
  81.           AddField (3, TRUE, Length(S), Position, S[1]);
  82.           S := 'Just a message';
  83.           AddField (6, TRUE, Length(S), Position, S[1]);
  84.           S := 'WhatEver/386 v0.0';
  85.           AddField (7, TRUE, Length(S), Position, S[1]);
  86.  
  87.           With Hdr Do
  88.           Begin
  89.             ReservedWord := 0;
  90.             SubfieldLen    := Position;
  91.             TimesRead    := 0;
  92.             MsgIdCRC     := -1;
  93.             ReplyCRC     := -1;
  94.             ReplyTo      := 0;
  95.             Reply1st     := 0;
  96.             ReplyNext    := 0;
  97.             DateWritten    := 0;
  98.             DateReceived := 0;
  99.             DateProcessed:= 0;
  100.             Attribute    := MSG_LOCAL Or MSG_PRIVATE Or MSG_TYPEECHO;
  101.             Attribute2   := 0;
  102.             PasswordCRC  := -1;
  103.             Cost         := 0;
  104.           End; { With }
  105.  
  106.           StoreMsgHdr(MsgNo);
  107.           WriteFile(HdrHandle, WorkBuf^, Position);
  108.  
  109.           Inc(HdrInfo.ActiveMsgs);
  110.           UpdHdrInfo(True);
  111.  
  112.         End { If }
  113.         Else
  114.           WriteLn ('Unable to lock JAM base ''', BaseName,'''');
  115.  
  116.       End { If }
  117.       Else
  118.         WriteLn ('Unable to open JAM base ''', BaseName,'''');
  119.  
  120.       Dispose (WorkBuf);
  121.       Dispose (JAMMsg);
  122.     End { If }
  123.     Else
  124.       WriteLn ('Unable to allocate Work Buffer memory');
  125.   End; { With }
  126. End.
  127.